package com.ruoyi.baseData.controller;

import com.ruoyi.baseData.domain.dto.TeamDto;
import com.ruoyi.baseData.service.TeamService;
import com.ruoyi.baseData.service.TeamUserService;
import com.ruoyi.common.core.domain.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/team")
public class TeamController {
    @Autowired
    TeamService teamService;

    @Autowired
    TeamUserService teamUserService;

    @PostMapping("/getTeamByPage")
    public R export(@RequestBody TeamDto materialDto)
    {
        return R.ok(teamService.getTeamByPage(materialDto));
    }

    @PostMapping("/addTeam")
    public R addTest(@RequestBody TeamDto materialDto){
        teamService.addTeam(materialDto);
        return R.ok("添加成功");
    }

    @PostMapping("/delTeam")
    public R delTest(@RequestBody TeamDto materialDto){
        teamService.delTeam(materialDto);
        return R.ok("删除成功");
    }

    @PostMapping("/updateTeam")
    public R updateTest(@RequestBody TeamDto materialDto){
        teamService.updateTeam(materialDto);
        return R.ok("锁定成功");
    }

    @PostMapping("/getUserByTeamId")
    public R getUserByTeamId(@RequestBody TeamDto materialDto){
//        teamService.getUserByTeamId(materialDto);
        return R.ok(teamService.getUserByTeamId(materialDto));
    }


    @PostMapping("/addTeamUser")
    public R addTeamUser(@RequestBody TeamDto materialDto){
//        teamService.getUserByTeamId(materialDto);
        teamService.addTeamUser(materialDto);
        return R.ok("添加成功");
    }

    @PostMapping("/getUserNameByTeamId")
    public R getUserNameByTeamId(@RequestBody TeamDto materialDto){
//        teamService.getUserByTeamId(materialDto);
//        teamUserService.getByTeamId(materialDto.getId());
        return R.ok(teamUserService.getByTeamId(materialDto.getId()));
    }



}
